package com.topnav.mc.admin.entity.wrapper;

import com.topnav.mc.admin.entity.param.DeviceOnlineTotalParam;
import com.topnav.mc.base.mc.McWrapper;
import org.springframework.util.StringUtils;

/**
 * @Author: kenny
 * @Date: 2023/10/31 15:20
 */
public class DeviceOnlineTotalWrapper extends McWrapper<DeviceOnlineTotalParam> {
    public DeviceOnlineTotalWrapper(DeviceOnlineTotalParam entity) {
        super(entity);
        if (this.permissionGrade != null ){
            if (this.permissionGrade.getPermissionLevel() == 1){
                this.eq("d.user_id",this.permissionGrade.getUserId());
            }else if (this.permissionGrade.getPermissionLevel() == 2){
                this.eq("d.org_id",this.permissionGrade.getOrgId());
            }else if (this.permissionGrade.getPermissionLevel() == 3 || this.permissionGrade.getPermissionLevel() == 4){
                this.likeRight("o.path",this.permissionGrade.getOrgPath());
            }
        }
        if (entity != null) {
            if (entity.getId() != null) {
                this.eq("dot.id", entity.getId());
            }
            if (entity.getDeviceId() != null) {
                this.eq("dot.device_id", entity.getDeviceId());
            }

            if (entity.getFromTime() != null) {
                this.ge("dot.start_time", entity.getFromTime());
            }

            if (entity.getToTime() != null) {
                this.le("dot.end_time", entity.getToTime());
            }

            if (!StringUtils.isEmpty(entity.getDeviceCode())) {
                this.like("d.code", entity.getDeviceCode());
            }

            if (entity.getOrgId() != null) {
                this.eq("d.org_id", entity.getOrgId());
            }

            if (entity.getUserId() != null) {
                this.eq("d.user_id", entity.getUserId());
            }
        }
    }
}
